﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Xml;

namespace BlazeNotes.Core
{
    class Note
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }

        public string Title { get; set; }
        [NotMapped]
        public FlowDocument Content { get; set; }
        public string XamlContent
        {
            get
            {
                if (Content == null)
                    return string.Empty;

                Stream memoryStream = new MemoryStream();

                XamlWriter.Save(Content, memoryStream);
                memoryStream.Position = 0;
                var streamReader = new StreamReader(memoryStream);
                return streamReader.ReadToEnd();
            }
            set
            {
                Stream memoryStream = new MemoryStream();
                StreamWriter writer = new StreamWriter(memoryStream);
                writer.Write(value);
                //writer.Close();
                writer.Flush();
                memoryStream.Position = 0;
                Content = XamlReader.Load(memoryStream) as FlowDocument;
            }
        }
    }
}
